<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
<title>三尺山教育信息咨询有限公司后台管理系统</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/jslib/tools.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/themes/default/easyui.css" type="text/css"></link>
<link rel="stylesheet" href="${pageContext.request.contextPath}/jslib/jquery-easyui-1.3.1/themes/icon.css" type="text/css"></link>
</head>
<script type="text/javascript" charset="utf-8">
$(function() {
	$('#moduls_user_datagrid').datagrid({
		url : '${pageContext.request.contextPath}/userAction!query.action',
		fit : true,
		pagination : true,
		rownumbers : true,
		border : false,
		checkOnSelect : false,
		selectOnCheck : false,
		idField : 'userId',
		nowrap : false,
		columns : [ [ {
			title : '编号',
			field : 'id',
			width : 150,
			checkbox : true,
			hidden : true
		}, {
			title : '账号',
			field : 'name',
			width : 80
		}, {
			title : '密码',
			field : 'pwd',
			width : 250
		},{
			field : 'action1',
			title : '删除',
			width : 80,
			formatter : function(value, row, index) {
				if (row.id == '0') {
					return '系统角色';
				} else {
					//return formatString('<img onclick="moduls_user_editFun(\'{0}\');" src="{1}"/>&nbsp;&nbsp;&nbsp;<img onclick="moduls_user_deleteFun(\'{2}\');" src="{3}"/>&nbsp;&nbsp;&nbsp;<img onclick="moduls_user_modifyUserPassFun(\'{4}\');" src="{5}"/>', row.userId, '../jslib/jquery-easyui-1.3.1/themes/icons/pencil.png', row.userId, '../jslib/jquery-easyui-1.3.1/themes/icons/cancel.png', row.userId, '../jslib/jquery-easyui-1.3.1/themes/icons/lock_edit.png');
					return '<a href="javascript:void(0)" onclick="del(\''+row.id+'\')">删除</a>';
				}
			}
		}, {
			field : 'action',
			title : '修改密码',
			width : 80,
			formatter : function(value, row, index) {
				if (row.id == '0') {
					return '系统角色';
				} else {
					//return formatString('<img onclick="moduls_user_editFun(\'{0}\');" src="{1}"/>&nbsp;&nbsp;&nbsp;<img onclick="moduls_user_deleteFun(\'{2}\');" src="{3}"/>&nbsp;&nbsp;&nbsp;<img onclick="moduls_user_modifyUserPassFun(\'{4}\');" src="{5}"/>', row.userId, '../jslib/jquery-easyui-1.3.1/themes/icons/pencil.png', row.userId, '../jslib/jquery-easyui-1.3.1/themes/icons/cancel.png', row.userId, '../jslib/jquery-easyui-1.3.1/themes/icons/lock_edit.png');
					return '<a href="javascript:void(0)" onclick="modifyPwd(\''+row.id+'\',\''+row.name+'\')">修改密码</a>';
				}
			}
		} ] ],
		toolbar : [ {
			text : '增加',
			iconCls : 'icon-add',
			handler : function() {
				add();
			}
		} ]
	});
});

function add() {
	$('<div/>').dialog({
		href : '${pageContext.request.contextPath}/Admin/UserManager/addUser.jsp',
		width : 300,
		height : 200,
		modal : true,
		title : '添加账号',
		buttons : [ {
			text : '保存',
			iconCls : 'icon-save',
			handler : function() {
				var d = $(this).closest('.window-body');
				$('#moduls_fun_user_form').form('submit', {
					url : '${pageContext.request.contextPath}/userAction!add.action',
					success : function(result) {
						try {
							var r = $.parseJSON(result);
							if (r.success) {
								d.dialog('destroy');
								$('#moduls_user_datagrid').datagrid('load');
							}
							$.messager.show({
								title : '提示',
								msg : r.msg
							});
						} catch (e) {
							$.messager.alert('提示', result);
						}
					}
				});
			}
		}, {
			text : '取消',
			iconCls : 'icon-remove',
			handler : function() {
				$(this).closest('.window-body').dialog('destroy');
			}
		} ],
		onClose : function() {
			$(this).dialog('destroy');
		}
	});
}

function del(id) {
	$.messager.confirm('确认', '您是否要删除改账号？', function(r) {
		if (r) {
			$.ajax({
				url : '${pageContext.request.contextPath}/userAction!delete.action',
				data : {
					id : id
				},
				dataType : 'json',
				success : function(result) {
					if (result.success) {
						$('#moduls_user_datagrid').datagrid('load');
					}
					$.messager.show({
						title : '提示',
						msg : result.msg
					});
				}
			});
		}
	});
}

function modifyPwd(id,name) {
	$('<div/>').dialog({
		href : '${pageContext.request.contextPath}/Admin/UserManager/modifyUserPass.jsp',
		width : 300,
		height : 200,
		modal : true,
		title : '修改密码',
		buttons : [ {
			text : '保存',
			iconCls : 'icon-save',
			handler : function() {
				var d = $(this).closest('.window-body');
				$('#moduls_fun_user_form').form('submit', {
					url : '${pageContext.request.contextPath}/userAction!modify.action',
					success : function(result) {
						try {
							var r = $.parseJSON(result);
							if (r.success) {
								d.dialog('destroy');
							}
							$.messager.show({
								title : '提示',
								msg : r.msg
							});
						} catch (e) {
							$.messager.alert('提示', result);
						}
					}
				});
			}
		}, {
			text : '取消',
			iconCls : 'icon-remove',
			handler : function() {
				$(this).closest('.window-body').dialog('destroy');
			}
		} ],
		onClose : function() {
			$(this).dialog('destroy');
		},
		onLoad : function() {
			$('#moduls_fun_user_form input[name=id]').val(id);
			$('#moduls_fun_user_form input[name=name]').val(name);
		}
	});
}
</script>
<body>
<table id="moduls_user_datagrid"></table>
</body>
</html>